package com.erlin.common.vo;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.http.HttpStatus;

/**
 * 统一的返回体
 *
 * @author Sola
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class ResponseVo<T> {
    /**
     * 响应码
     */
    private int code;
    /**
     *
     */
    private T data;
    /**
     * 响应信息
     */
    private String message;

    private static final String DEFAULT_MESSAGE = "OK";

    public static <T> ResponseVo<T> of(int code, T data, String message) {
        return new ResponseVo<T>(code, data, message);
    }

    public static <T> ResponseVo<T> ok(T data) {
        return of(HttpStatus.OK.value(), data, DEFAULT_MESSAGE);
    }

    public static <T> ResponseVo<T> exception(String message) {
        return of(HttpStatus.INTERNAL_SERVER_ERROR.value(), null, message);
    }
}